/*********************************************************************
	Rhapsody	: 7.5 
	Login		: kbe
	Component	: DefaultComponent 
	Configuration 	: CodeConfig
	Model Element	: Acceptor
//!	Generated Date	: Thu, 27, Sep 2012  
	File Path	: DefaultComponent\CodeConfig\Acceptor.h
*********************************************************************/

#ifndef Acceptor_H
#define Acceptor_H

//#[ ignore
#ifdef _MSC_VER
// disable Microsoft compiler warning (debug information truncated)
#pragma warning(disable: 4786)
#endif
//#]

//## auto_generated
#include <oxf\oxf.h>
//## auto_generated
#include <string>
//## auto_generated
#include <algorithm>
//## auto_generated
#include "Default.h"
//## class Acceptor
#include "EventHandler.h"
//## auto_generated
#include "SOCK_WrapperFacade.h"
//## dependency ThreadPool
#include "ThreadPool.h"
//## auto_generated
#include "Reactor.h"
//## auto_generated
class Reactor;

//## package Default

//## class Acceptor
template <class SERVICE_HANDLER, class IPC_ACCEPTOR> class Acceptor : public EventHandler {
    ////    Friends    ////
    
    ////    Constructors and destructors    ////
    
private :

    IPC_ACCEPTOR* acceptor_;		//## attribute acceptor_

public :

    //## operation Acceptor(Reactor *,INET_Addr*,ThreadPool*,bool)
    inline Acceptor(Reactor * reactor, INET_Addr* addr, ThreadPool* threadPool, bool registerHandle = true) {
        //#[ operation Acceptor(Reactor *,INET_Addr*,ThreadPool*,bool)
        acceptor_ = new IPC_ACCEPTOR(*addr); 
        handle = (HANDLE)acceptor_->get_handle();
        type = ACCEPT_EVENT;
        IsActive = false;
        itsReactor = reactor;
        threadPool_ = threadPool;         
        if (registerHandle)
        	itsReactor->registerHandler(*this, ACCEPT_EVENT);
        //#]
    }
    
    //## auto_generated
    Acceptor();
    
    //## auto_generated
    virtual ~Acceptor();
    
    ////    Operations    ////
    
    //## operation Acceptor(Reactor *,HANDLE)
    inline Acceptor(Reactor * reactor, const HANDLE& h) {
        //#[ operation Acceptor(Reactor *,HANDLE)
        handle = h;
        type = ACCEPT_EVENT;
        itsReactor = reactor;
        //#]
    }
    
    //## operation handleEvent(HANDLE,Event_Type)
    inline virtual int handleEvent(HANDLE h, Event_Type& et) {
        //#[ operation handleEvent(HANDLE,Event_Type)
        if (et == type)
        {   
        	SOCK_Stream *client_connection = new SOCK_Stream();
        	acceptor_->accepting(*client_connection); 
        	SERVICE_HANDLER *eventHandler = new SERVICE_HANDLER(itsReactor, client_connection);
            LF_EventHandler *LFEventHandler = new LF_EventHandler(itsReactor, eventHandler, threadPool_, READ_EVENT);
        }
        return 0;
        //#]
    }

protected :

    //## auto_generated
    IPC_ACCEPTOR* getAcceptor_() const;

public :

    //## auto_generated
    ThreadPool* getThreadPool_() const;
    
    //## auto_generated
    void setThreadPool_(ThreadPool* p_threadPool_);

protected :

    ThreadPool* threadPool_;		//## attribute threadPool_
    
    //## auto_generated
    void setAcceptor_(IPC_ACCEPTOR* p_acceptor_);
};

//## package Default

//## class Acceptor
template <class SERVICE_HANDLER, class IPC_ACCEPTOR> ThreadPool* Acceptor<SERVICE_HANDLER, IPC_ACCEPTOR>::getThreadPool_() const {
    return threadPool_;
}

template <class SERVICE_HANDLER, class IPC_ACCEPTOR> void Acceptor<SERVICE_HANDLER, IPC_ACCEPTOR>::setThreadPool_(ThreadPool* p_threadPool_) {
    threadPool_ = p_threadPool_;
}

template <class SERVICE_HANDLER, class IPC_ACCEPTOR> IPC_ACCEPTOR* Acceptor<SERVICE_HANDLER, IPC_ACCEPTOR>::getAcceptor_() const {
    return acceptor_;
}

template <class SERVICE_HANDLER, class IPC_ACCEPTOR> void Acceptor<SERVICE_HANDLER, IPC_ACCEPTOR>::setAcceptor_(IPC_ACCEPTOR* p_acceptor_) {
    acceptor_ = p_acceptor_;
}

template <class SERVICE_HANDLER, class IPC_ACCEPTOR> Acceptor<SERVICE_HANDLER, IPC_ACCEPTOR>::Acceptor() {
}

template <class SERVICE_HANDLER, class IPC_ACCEPTOR> Acceptor<SERVICE_HANDLER, IPC_ACCEPTOR>::~Acceptor() {
}

#endif
/*********************************************************************
	File Path	: DefaultComponent\CodeConfig\Acceptor.h
*********************************************************************/
